package org.xq.shop.maxaishop.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xq.shop.maxaishop.entity.XqColle;
import org.xq.shop.maxaishop.service.XqColleService;
import org.xq.shop.maxaishop.util.MailUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * (XqColle)表控制层
 *
 * @author makejava
 * @since 2021-06-27 11:57:15
 */
@Api( tags = "用户收藏操作")
@RestController
@RequestMapping("xqColle")
public class XqColleController {
    /**
     * 服务对象
     */
    @Resource
    private XqColleService xqColleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("根据主键查询单个订单信息")
    @ApiImplicitParam(name = "id", value = "商品id", required=true,paramType="query" )
    @GetMapping("selectOne")
    public XqColle selectOne(Integer id) {
        return this.xqColleService.queryById(id);
    }

    /**
     * 添加收藏
     * @param cid
     * @param uid
     * @return
     */
    @ApiOperation("用户收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name="cid",value="商品id",required=true,paramType="query"),
            @ApiImplicitParam(name="uid",value="用户id",required=true,paramType="query"),
    })
    @PostMapping("insert")
    public int insert(Integer cid, Integer uid){
        int insert = this.xqColleService.insert(uid, cid);
        return insert;
    }

    /**
     * 展示用户收藏
     * @param uid
     * @return
     */
    @ApiOperation("展示用户收藏")
    @ApiImplicitParam(name="uid",value="用户id",required=true,paramType="query")
    @GetMapping("selectByuid")
    private List<XqColle> selectByuid(Integer uid){
        List<XqColle> xqColles = this.xqColleService.selectByuid(uid);

        return xqColles;

    }

    /**
     * 删除收藏
     * @param sid
     * @return
     */
    @ApiOperation("用户删除收藏")
    @ApiImplicitParam(name="sid",value="收藏id",required=true,paramType="query")
    @GetMapping("deleteById")
    public boolean deleteById(Integer sid){
        System.out.println(sid);
         return this.xqColleService.deleteById(sid);
    }

    /**
     * 查询是否已经收藏
     * @param uid
     * @param cid
     * @return
     */
    @ApiOperation("用户是否已经收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name="uid",value="用户id",required=true,paramType="query"),
            @ApiImplicitParam(name="cid",value="商品id",required=true,paramType="query"),
    })
    @PostMapping("selectBycid")
    public XqColle deleteById(Integer uid, Integer cid){
        return this.xqColleService.selectBycid(uid,cid);
    }



}
